import request from "@/utils/request";

// 获取配置参数
export function getParam(paramStr) {
  return request({
    url: "/ait/common/app/parm",
    method: "get",
    params: {parm:paramStr}
  });
}

// 获取配置参数
export function getParamArray(paramStr,field,value) {
  return request({
    url: "/ait/common/app/parmArray",
    method: "get",
    params: {parm:paramStr,fieldName:field,fieldValue:value}
  });
}

// 保存配置参数
export function saveParam(paramStr,paramObject){
  return request({
    url: "/ait/common/app/parm",
    method: "post",
    params:{parm:paramStr},
    data: paramObject
  });
}

// 保存配置参数
export function saveParamArray(paramStr,field,paramObject,isDelete=false){
  return request({
    url: "/ait/common/app/parmArray",
    method: "post",
    params:{parm:paramStr,fieldName:field,isDelete},
    data: paramObject
  });
}

// 获取treeData所有节点数据
export function getAllNodeKeys(nodeList,childrenField,keyField) {
  let keys = [];
  const traverse = (nodes) => {
    for (let node of nodes) {
      keys.push(node[keyField]);
      if (node[childrenField] && node[childrenField].length > 0) {
        traverse(node[childrenField]);
      }
    }
  };
  traverse(nodeList);
  return keys;
}


